home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / or / or_search.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  4.1 KB  |  241 lines

  1. /* or_search.c: misc functions to do with locating or bits */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/or/RCS/or_search.c,v 6.0 1991/12/18 20:23:08 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/or/RCS/or_search.c,v 6.0 1991/12/18 20:23:08 jpo Rel $
  9.  *
  10.  * $Log: or_search.c,v $
  11.  * Revision 6.0  1991/12/18  20:23:08  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "or.h"
  19. #include "util.h"
  20.  
  21.  
  22.  
  23.  
  24. /* ---------------------  Begin  Routines  -------------------------------- */
  25.  
  26.  
  27.  
  28.  
  29. OR_ptr or_lastpart (or)
  30. OR_ptr or;
  31. {
  32.     PP_DBG (("or_util.c/or_lastpart()"));
  33.  
  34.     if (or == NULLOR)
  35.     return NULLOR;
  36.  
  37.     while (or -> or_next != NULLOR)
  38.     or = or -> or_next;
  39.  
  40.     return or;
  41. }
  42.  
  43.  
  44.  
  45.  
  46. OR_ptr or_find (tree, type, ddname)
  47. OR_ptr          tree;
  48. int             type;
  49. char            *ddname;
  50. {
  51.     OR_ptr      ptr;
  52.  
  53.     PP_DBG (("or_util.c/or_find()"));
  54.  
  55.     for (ptr = tree; ptr != NULLOR; ptr = ptr -> or_next)
  56.     if (ptr -> or_type == type)  
  57.         if (ptr -> or_type != OR_DD || ddname == NULLCP)
  58.             return ptr;
  59.         else 
  60.             if (lexequ (ptr -> or_ddname, ddname) == 0)
  61.                 return ptr;
  62.     return NULLOR;
  63. }
  64.  
  65.  
  66.  
  67.  
  68. int or_cmp (or1, or2)
  69. OR_ptr          or1;
  70. OR_ptr          or2;
  71. {
  72.  
  73.     PP_DBG (("or_util.c/or_cmp:  ('%d', '%s', '%s')  ('%d', '%s', '%s')",
  74.       or1 -> or_type, or1 -> or_ddname, or1 -> or_value,
  75.       or2 -> or_type, or2 -> or_ddname, or2 -> or_value));
  76.  
  77.     if (or1 -> or_type != or2 -> or_type
  78.     || lexequ (or1 -> or_value, or2 -> or_value) != 0)
  79.         return FALSE;
  80.  
  81.     if (or1 -> or_type == OR_DD
  82.     && lexequ (or1 -> or_ddname, or2 -> or_ddname) != 0)
  83.         return FALSE;
  84.  
  85.     return TRUE;
  86. }
  87.  
  88.  
  89.  
  90.  
  91. /* --- *** ---
  92. or_locate: given a or tree, find the first component
  93.        of the specified type.
  94. --- *** --- */
  95.  
  96. OR_ptr  or_locate (or, type)
  97. OR_ptr          or;
  98. int             type;
  99. {
  100.     register OR_ptr   orp;
  101.  
  102.     PP_DBG (("Lib/or/or_locate (%d)", type));
  103.     for (orp = or; orp != NULLOR && or -> or_type <= type;
  104.      orp = orp -> or_next)
  105.         if (orp -> or_type == type)
  106.             return orp;
  107.     return NULLOR;
  108. }
  109.  
  110.  
  111.  
  112.  
  113. /* --- *** ---
  114. or_value: given an or tree, return the value of the first element of a
  115.       given type.
  116. --- *** --- */
  117.  
  118. char*   or_value (or, type)
  119. OR_ptr  or;
  120. int     type;
  121. {
  122.     register OR_ptr  orp;
  123.  
  124.     PP_DBG (("Lib/or/or_value (%d)", type));
  125.     for (orp = or; orp != NULLOR && or -> or_type <= type;
  126.      orp = orp -> or_next)
  127.         if (type == orp -> or_type)
  128.             return (orp -> or_value);
  129.     return NULLCP;
  130. }
  131.  
  132.  
  133.  
  134.  
  135. /* --- *** ---
  136. or_add_atsigns: For any missing OR Components insert that
  137.         component as a NULL ("@") attribute
  138. --- *** --- */
  139.  
  140. int or_add_atsigns (orp)
  141. OR_ptr  *orp;
  142. {
  143.     OR_ptr  or,
  144.         old,
  145.         new;
  146.     int     type;
  147.  
  148.     PP_DBG (("Lib/or_add_atsigns()"));
  149.  
  150.     old = *orp;
  151.     or = new = NULLOR;
  152.  
  153.     if (old == NULLOR) {
  154.         PP_LOG (LLOG_EXCEPTIONS,
  155.             ("Lib/or_add_atsigns - No OR specified"));
  156.         return NOTOK;
  157.     }
  158.  
  159.  
  160.     for (type = OR_C; type < OR_OU; type++) {
  161.  
  162.         /* -- add the attribute as NULL ("@") -- */
  163.         if ((or = or_find (old, type, NULLCP)) == NULLOR)
  164.             or = or_new_aux (type, NULLCP, "@", OR_ENC_PP);
  165.         else
  166.             old = old -> or_next;
  167.  
  168.         if ((new = or_add (new, or, TRUE)) == NULLOR)
  169.             return NOTOK;
  170.  
  171.         if (old == NULLOR)
  172.             break;
  173.     }
  174.  
  175.  
  176.     for (;;) {
  177.         if (old == NULLOR)
  178.             break;
  179.         if (old -> or_type < OR_OU)
  180.             continue;
  181.         or = old;
  182.         old = old -> or_next;
  183.         if (or_add (new, or, FALSE) == NULLOR)
  184.             return NOTOK;
  185.     }
  186.  
  187.     *orp = new;
  188.     return OK;
  189. }
  190.  
  191.  
  192.  
  193.  
  194. /* --- *** ---
  195. or_delete_atsigns: For any NULL OR Components delete
  196.            that component
  197. --- *** --- */
  198.  
  199. int or_delete_atsigns (ptr)
  200. OR_ptr  *ptr;
  201. {
  202.     OR_ptr  old, top, or,
  203.         bk, fw, rm;
  204.  
  205.     PP_DBG (("Lib/or_delete_atsigns()"));
  206.  
  207.     old = top = *ptr;
  208.  
  209.     if (old == NULLOR) {
  210.         PP_LOG (LLOG_EXCEPTIONS,
  211.             ("Lib/or_delete_atsigns - No OR specified"));
  212.         return NOTOK;
  213.     }
  214.  
  215.  
  216.     for (or = old; or; or = fw) {
  217.         bk = or -> or_prev;
  218.         fw = or -> or_next;
  219.         rm = or;
  220.         if (or -> or_type >= OR_OU)
  221.             break;
  222.         if (lexequ (or -> or_value, "@") == 0) {
  223.             if (bk) {
  224.                 bk -> or_next = fw;
  225.                 if (or == *ptr ||
  226.                     (lexequ (top -> or_value, "@") == 0))
  227.                         top = fw;
  228.             }
  229.             else
  230.                 top = fw;
  231.             fw -> or_prev = bk;
  232.             rm -> or_next = rm -> or_prev = NULLOR;
  233.             or_free (rm);
  234.         }
  235.     }
  236.  
  237.  
  238.     *ptr = top;
  239.     return OK;
  240. }
  241.